// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import qs from 'qs'

//路由文件
import router from './router'

//axios网络请求
import axios from 'axios'
import VueAxios from 'vue-axios'
Vue.use(VueAxios, axios)

//vuex存储
import store from './store/store'


import MuseUI from 'muse-ui'
import 'muse-ui/dist/muse-ui.css'
import './styles/red.less'
Vue.use(MuseUI);

import wcSwiper from 'wc-swiper'
import 'wc-swiper/style.css'
Vue.use(wcSwiper);

//videojs视频播放器
require('video.js/dist/video-js.css')
import VueVideoPlayer from 'vue-video-player'

Vue.use(VueVideoPlayer)

import {Loading} from 'element-ui'
Vue.use(Loading)

import soocStorage from './util/localStorage'

Vue.config.productionTip = false
Vue.axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
// Vue.axios.defaults.baseURL = 'http://devytwldx.sooc.com/';
Vue.axios.interceptors.request.use(
  config => {
    // 在发送请求之前做某件事
    if (
      config.method === "post" ||
      config.method === "put" ||
      config.method === "delete"
    ) {
      // 序列化
      //如果是登录的，自动添加token的参数
      let token = soocStorage.wrapJsonStorage('token');
      if( token.size() > 0 ){
        if(config.data == undefined || config.data == 'undefined'){
          config.data = {};
        }
        config.data.oauth_token = token.get('oauth_token');
        config.data.oauth_token_secret = token.get('oauth_token_secret');
      }
      config.data = qs.stringify(config.data);
    }

    // 若是有做鉴权token , 就给头部带上token
    // if (localStorage.token) {
    //   config.headers.Authorization = localStorage.token;
    // }
    return config;
  },
  error => {
    // Message({
    //   //  饿了么的消息弹窗组件,类似toast
    //   showClose: true,
    //   message: error,
    //   type: "error.data.error.message"
    // });
    return Promise.reject(error.data.error.message);
  }
);

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  template: '<App/>',
  components: {App},
  store
})
